import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// 引入路径模块
import path from 'path'

// 引入自动导入插件
import AutoImport from 'unplugin-auto-import/vite'

// https://vite.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      'vue': 'vue/dist/vue.esm-bundler.js' // 定义vue的别名，如果使用其他的插件，可能会用到别名
    },
  },
  server: {
    proxy: {
      '/shop': {
        // target: 'http://www.fast.me/shop',
        // target: 'http://localhost:8080', //本地JAVA后端接口地址
        target: 'https://fast.constqr.cn/shop', //线上接口地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/shop/, ''),
      },
      '/chat': {
        target: 'http://api.qingyunke.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/chat/, ''),
      }
    }
  },
  plugins: [
    vue(), 
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        {
          '@/api/index.js': [
            ['default', 'Api'],
          ],
          'vant': [
            ['showSuccessToast', 'success'], ['showFailToast', 'error'], ['showConfirmDialog', 'Dialog'],['showToast', 'toast']
          ]
        }
      ]
    })
  ],
})
